package com.itheima.demo03JDBC增_删_改数据重点;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/*
    建议Java里面写SQL语句,可以先在SQLYog中写好.复制到代码
 */
public class Demo03 {
    public static void main(String[] args) throws Exception {
        // 1.注册驱动(自动注册)
        // 2.获取Connection连接
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/day18", "root", "root");
        // 3.获取Statement(小货车)
        Statement stmt = conn.createStatement();
        String sql = "INSERT INTO user VALUES ( null,'tom', '123');";
//        String sql1 = "UPDATE user SET name='tony' WHERE id=5;";

        // 4.执行SQL语句
        int row = stmt.executeUpdate(sql);
//        int row1= stmt.executeUpdate(sql1);
        System.out.println("行数为："+row);

        // 5.处理结果
        // 6.释放资源
        stmt.close();
        conn.close();
    }
}
